package com.bawei.databinding_recyclerview;

import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;

import androidx.databinding.BindingAdapter;

public class ImageViewBindingAdapter {
    @BindingAdapter("android:image")
    public static void setImageUrl(ImageView view, String imageUrl) {
       if(TextUtils.isEmpty(imageUrl)){
           view.setImageResource(R.drawable.ic_launcher_background);
       }else{
           Glide.with(view)
                   .load(imageUrl)
                   .placeholder(R.drawable.ic_launcher_background)
                   .transform(new CenterCrop())
                   .into(view);
       }
    }
}
